import { request } from "@/utils/request"
import type {ConsultOrderItem,PartialConsult,KnowledgeParams,KnowledgePage, DoctorPage, PageParams,TopDep,Image,ConsultOrderPreData, ConsultOrderPreParams } from '@/types/consult'
import { ConsultTime } from '@/enums'
import type { ConsultOrderListParams, ConsultOrderPage } from '@/types/consult'
// 首页-查询推荐/减脂/饮食健康/关注页面--百科文章列表
export const queryFoodAPI = (params:KnowledgeParams) => {
  return request.get<KnowledgePage>('/patient/home/knowledge', {params})
}
export const getDoctorPage = (params: PageParams) =>
  request.get<DoctorPage>('/home/page/doc', { params })
  

// 关注操作
export const attentionDoctorAPI = (type:string,id:string) => {
  return request.post('/like', {
    type,
    id
  })
}
// 获取所有科室
export const getAllDep = () => request.get<TopDep[]>('/dep/all')
// 提交图片
export const uploadImage = (file: File) => {
  const fd = new FormData()
  fd.append('file', file)
  return request.post<Image>('/upload', fd)
}


// 拉取预支付订单信息
export const getConsultOrderPre = (params: ConsultOrderPreParams) =>
  request.get<ConsultOrderPreData>('/patient/consult/order/pre', { params })

// 生成订单
export const createConsultOrder = (data: PartialConsult) =>
  request.post<{ id: string }>('/patient/consult/order', data)

// 获取支付地址  0 是微信  1 支付宝
export const getConsultOrderPayUrl = (data: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => request.post<{ payUrl: string }>('/patient/consult/pay', data)


// 患病时间
export const timeOptions = [
  { label: '一周内', value: ConsultTime.Week },
  { label: '一月内', value: ConsultTime.Month },
  { label: '半年内', value: ConsultTime.HalfYear },
  { label: '大于半年', value: ConsultTime.More }
]
// 是否就诊过
export const flagOptions = [
  { label: '就诊过', value: 0 },
  { label: '没就诊过', value: 1 }
]

export const getConsultOrderDetail = (orderId: string) =>
  request.get<ConsultOrderItem>('/patient/consult/order/detail', { params: { orderId } })
  

// 查看处方
export const getPrescriptionPic = (id: string) =>
  request.get<{ url: string }>(`/patient/consult/prescription/${id}`)

// 评价问诊
export const evaluateConsultOrder = (data: {
  docId: string // 医生ID
  orderId: string // 订单ID
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => request.post<{ id: string }>('/patient/order/evaluate', data)

// 获取问诊订单记录列表
export const getConsultOrderList = (params: ConsultOrderListParams) =>
  request.get<ConsultOrderPage>('/patient/consult/order/list', { params })

// 取消订单
export const cancelOrder = (id: string) => request.put(`/patient/order/cancel/${id}`)

// 删除订单
export const deleteOrder = (id: string) => request.delete(`/patient/order/${id}`)